﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL.DateSet.ModelTableAdapters;
using DAL.DateSet;
using DAL;
namespace BLL.Wrapper
{
    public class ModelWrapper : ModelTableAdapter
    {
        public Model.ModelDataTable getall()
        {
            return GetData();
        }

        public void addARecord(Model.ModelRow row)
        {
            Insert(row.goodsID,row.isDefault, row.length, row.width, row.height, row.modelSrc, row.packageSize, row.packageWight, row.modelCreator, row.modelCreateDate);
        }

        public void deleteByID(int id)
        {
            string sql = "delete from ModifyRecord where modelID = " + id.ToString();
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            helper.initOle();
            helper.delete(sql);
        }

        public void updateARecord(Model.ModelRow row)
        {
            Model.ModelDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (Convert.ToInt32(table.Rows[i]["modelID"]) == row.modelID)
                {
                    table.Rows[i]["goodsID"] = row.goodsID;
                    table.Rows[i]["isDefault"] = row.isDefault;
                    table.Rows[i]["length"] = row.length;
                    table.Rows[i]["width"] = row.width;

                    table.Rows[i]["modifyDetail"] = row.height;
                    table.Rows[i]["modelSrc"] = row.modelSrc;
                    table.Rows[i]["packageSize"] = row.packageSize;
                    table.Rows[i]["packageWight"] = row.packageWight;
                    table.Rows[i]["modelCreator"] = row.modelCreator;
                    table.Rows[i]["modelCreateDate"] = row.modelCreateDate;
                    break;
                }
            }
            Update(table);
        }
    }
}
